package com.xy.mainp.novel.fragment.mybook;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.xy.mainp.MyBookBinding;
import com.xy.mainp.R;
import com.xy.mainp.base.LazyFragment;
import com.xy.view.AutoScrollViewPager;

import java.util.List;

/**
 * Created by John on 2016/11/28.
 */

public class MyBookFragment extends LazyFragment {

    private String url;
    private MyBookBinding bookBinding;

    public MyBookFragment(){

    }

    public MyBookFragment(String url){
        this.url = url;
    }
    private int num = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bookBinding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.fragment_my_book,null,false);
        setContentView(bookBinding.getRoot());
        bookBinding.vpMyBook.setAdapter(new testAdapter());  //setAdapter调用了stopScroll 所以要调用startScroller
        bookBinding.vpMyBook.setDelay(2000);
        bookBinding.vpMyBook.setAutoDelayScroll(800);
        bookBinding.vpMyBook.startScroll();
    }
    class testAdapter extends AutoScrollViewPager.AutoScrollPagerAdapter{
        private int[] colors = new int[]{Color.BLUE,Color.GREEN,Color.RED};

        @Override
        public int getDataCount() {
            return colors.length;
        }

        @Override
        public View createView(Context context, final int position) {
            ImageView imageView = new ImageView(context);
            imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            imageView.setBackgroundColor(colors[position]);
            return imageView;
        }
    }
}
